#pragma once
#include <vector>
#include "Vector3.h"
#include "MyMatrix.h"
#include "Quaternion.h"
#include "MyColor.h"
#include "Triangle.h"
#include "BoundingBox.h"

class Colider
{
public:
	MyColor _color;

	static void CalulateVelocitesAfterColision(Vector3<float>& v1, double m1,
												Vector3<float>& v2, double m2,
												double CoefficientOfRestitution);
	static void ForceColide(Colider* box1, Vector3<float> b1Hit,
							Colider* box2, Vector3<float> b2Hit,
							Vector3<float> ColisonNormal, float overLap);

private:
	// the mass of the object
	float _mass; 

	// location of the object is space
	Vector3<float> _position;

	// the veloctiy of the object
	Vector3<float> _velocity;

	// scale information broken down into a vector 
	Vector3<float> _scale;

	// skew information broken into a vector
	Vector3<float> _skew;

	// The model of points that will not be manipulated but
	// represent the shape of the object relitive to its center
	std::vector<Triangle> _model;

	// rotattion of some sort
	std::vector<Triangle> _transformed;

	Vector3<float> _momentOfInirta;

	// the rotation of the objecet in 3d space
	Quaternion _rotation;

	// the angular velocity represented at a quaternian 
	Quaternion _angularVelocity;

	// Forces being applied to the object
	Vector3<float> _liniarForces;
	Vector3<float> _torque;

	Vector3<float> _angularMomentum;


public:
	Colider(std::vector<Triangle> shape, Vector3<float> location, float mass);
	Colider(std::vector<Triangle> shape, Vector3<float> location, float mass, Quaternion rotation);
	Colider(std::vector<Triangle> shape, Vector3<float> location, float mass, Quaternion rotation, Vector3<float> scale);
	~Colider(void);

	void Update(void);
	void Draw(void);
	void ManualDraw();
	void DrawNormals();

	void TranslateTo(Vector3<float> destination);
	void Translate(Vector3<float> distance);

	Vector3<float> Position();

	Vector3<float> MOI();

	Vector3<float>& Velocity(void);
	Vector3<float>& Scale(void); 
	Vector3<float>& Skew(void); 
	Quaternion& Rotation(void);

	void Rotate(Quaternion amount);
	void RotateGlobal(Quaternion amount);

	void AddForce(Vector3<float> force, Vector3<float> radious);

	Vector3<float> PointOnShape(Vector3<float> start);

	Vector3<float> PointOnModel(Vector3<float> start);

	BoundingBox BBox();

	bool SATTest(Colider* obj, Vector3<float>& myColide, Vector3<float>& objColide, Vector3<float>& colisionNormal, float& overLap);
	bool SATTest(Colider obj, Vector3<float>& myColide, Vector3<float>& objColide, Vector3<float>& colisionNormal, float& overLap);

	std::vector<Triangle> TransformedModel();

	static const Vector3<float> Z_FORWARD;

	void TransformPoints();

private:
	void makeMOI(void);

	void ApplyForces();
	void ClearForces();

	bool SATPoint(Vector3<float> point, Vector3<float>& colisionNormal, float& overLap);

	MyMatrix ScaleMatrix();
	MyMatrix TranslateMatrix();
	MyMatrix SkewMatrix();
};

